package com.naishuo.bigevent.service.impl;

import com.naishuo.bigevent.mapper.CategoryMapper;
import com.naishuo.bigevent.pojo.Category;
import com.naishuo.bigevent.service.CategoryService;
import com.naishuo.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceimpl implements CategoryService {

    @Autowired//忘记装配了
    private CategoryMapper categoryMapper;
    @Override
    public void addcategory(Category category) {

        Map<String,Object> map = ThreadLocalUtil.get();
        category.setCreateUser((Integer) map.get("id"));
        categoryMapper.addcategory(category);
    }

    @Override
    public List<Category> findAll() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer) map.get("id");
        System.out.printf(String.valueOf(id));
        return categoryMapper.findAll(id);
    }

    @Override
    public List<Category> findAllByUserId(Integer id) {
        return categoryMapper.findAllByUserId(id);
    }

    @Override
    public void updateCategory(Category category) {

        Map<String,Object> map= ThreadLocalUtil.get();
        Integer id=(Integer) map.get("id");
        category.setCreateUser(id);
        categoryMapper.updateCategory(category);
    }

    @Override
    public void deleteCategory(Integer id) {

        System.out.println(id);
        categoryMapper.deleteCategory(id);
    }

}
